#ifndef XMLPARSER_H_
#define XMLPARSER_H_

#include <iostream>
#include <string>
#include "../../lib/pugixml/src/pugixml.hpp"
#include <map>

using namespace std;
using namespace pugi;

#define ERROR_MSG "node not found in params.xml" // error message used when could not found parameters for indicated ROS node

/**
 * Parses XML file holding the general system parameters (params.xml). \n
 * The extraction is done in a static manner- no instance should be created
 */
class XmlParser {

private:

	// no need to create an instance
	XmlParser() {}
	~XmlParser() {}

	/**
	 * Reads parameters out of indicated node in XML document. \n
	 * Parameters are updated in a map, where a key is parameter's name and value
	 * is parameter's value
	 * @param[in] param_node node in XML document holding parameters to be parsed
	 * @param[out] params parameters map to update
	 */
	static void readParams(xml_node param_node, map<string, string>& params);

	/**
	 * Trims all white spaces (space, new-line, tab) out of given string
	 * @param s string to trim
	 */
	static void trimAll(std::string &s);

	static xml_node findNode(string node_name) throw(const char*);

public:

	/**
	 * Extracts all necessary parameters, out of params.xml, for ROS node
	 * matching given name. \n
	 * Parameters are updated in a map, where a key is parameter's name and value
	 * is parameter's value
	 * @param[in] node_name name of ROS node to extract its parameters
	 * @param[in] task_name indicates which set of parameters is needed
	 * @param[out] params parameters map to update
	 */
	static void extractNodeData(string node_name, string task_name, map<string, string>& params) throw(const char*);

	/**
	 * Same as extractNodeData(string,string,map<string,string>), but used
	 * when the node has only one set of parameters
	 * @param[in] node_name name of ROS node to extract its parameters
	 * @param[out] params parameters map to update
	 */
	static void extractNodeData(string node_name, map<string, string>& params) throw(const char*);
};

#endif /* XMLPARSER_H_ */
